<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全选 反选 取消</title>
    <style>
        .selected {
            background-color: #528bcb;
            color: #ffffff;
            border-bottom: 1px solid #fff;
        }
    </style>
</head>
<script>
    window.onload = function () {

        var btns = document.querySelectorAll('button')
        var inputs = document.querySelectorAll('input')
        var lis = document.querySelectorAll('li')

        function all(isSelected, cName) {
            inputs.forEach((item, index) => {
                item.checked = isSelected
            })
            lis.forEach((item, index) => {
                item.className = cName
            })
        }
        // 全选
        btns[0].onclick = function () {
            inputs.forEach((item, index) => {
                item.checked = true
            })
            lis.forEach((item, index) => {
                item.className = "selected"
            })
        }
        //反选
        btns[1].onclick = function () {
            inputs.forEach((item, index) => {
                if (item.checked) {
                    item.checked = false
                } else {
                    item.checked = true
                }
            })
            // 取消
            btns[2].onclick = function () {
                all(false, '')
            }

        }
    }
</script>

<body>
    <button>全选</button>
    <button>反选</button>
    <button>取消</button>

    <ul>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
        <li><input type="checkbox">coding</li>
    </ul>

</body>

</html>